package com.chen.tliaswebtest.config;

import com.chen.tliaswebtest.interceptor.LogInInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author chen
 * @version 1.0
 * @create_date 2025/7/26
 * 配置类，添加拦截器
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    private final LogInInterceptor loginInterceptor;

    public WebConfig(LogInInterceptor loginInterceptor) {
        this.loginInterceptor = loginInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加拦截器，排除登录相关路径
        registry.addInterceptor(loginInterceptor)
                // 拦截所有路径
                .addPathPatterns("/**")
                // 排除登录路径
                .excludePathPatterns("/login", "/login/**");
    }
}
